﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNA.Mvc.Data.Entity;

namespace DNA.Mvc.Publishing.Data.Entity
{
    public class PubContext:UnitOfWorkBase<PubDB>, IPubContext
    {
        public PubContext(string nameOrConnectionString)
        {
            this.dbContext = new PubDB(nameOrConnectionString);
        }

        public PubContext()
        {
            this.dbContext = new PubDB();
        }

        private IArticleRepository articles;
        private ICategoryRepository categories;
        private ICommentRepository comments;
        private ITranslatedCopyRepository translatedCopies;
        private IRepository<History> versions;

        public IArticleRepository Articles
        {
            get 
            {
                if (articles == null)
                    articles = new ArticleRepository(dbContext);
                return articles;
            }
        }

        public ICategoryRepository Categories
        {
            get 
            {
                if (categories == null)
                    categories = new CategoryRepository(dbContext);
                return categories;
            }
        }

        public ICommentRepository Comments
        {
            get 
            {
                if (comments == null)
                    comments = new CommentRepository(dbContext);
                return comments;
            }
        }

        public ITranslatedCopyRepository TranslatedCopies
        {
            get 
            {
                if (translatedCopies == null)
                    translatedCopies = new TranslatedCopyRepository(dbContext);
                return translatedCopies;
            }
        }

        //protected override EntityRepositoryBase<PubDB, T> GenericRepository<T>()
        //{
        //    return new GenericPubEntityRepository<T>(dbContext);
        //}


        public IRepository<History> Versions
        {
            get 
            {
                if (versions == null)
                    versions = GenericRepository<History>();
                return versions;
            }
        }
    }
}
